package cn.xd.core.design.chain;

import cn.xd.common.exception.BizException;

import java.util.Objects;

/**
 * @author : mirzaLin
 * @data : 2023/11/19
 * @description : 责任链处理器
 **/
public class ChainHandler<T extends ChainRequest, R extends ChainResponse> {

    private final T t;

    private final R r;

    public ChainHandler(T t, R r) {
        Objects.requireNonNull(t);
        Objects.requireNonNull(r);
        this.t = t;
        this.r = r;
    }

    public R execute(Chain<T, R> chain) throws BizException {
        chain.accept(t, r);
        return this.r;
    }

    public T getRequest() {
        return t;
    }

    public R getResponse() {
        return r;
    }

}

